﻿namespace lighttool.tsbb.expr
{
    export class expr_return implements lighttool.tsbb.IBBAction_Flow
    {
        desc: lighttool.tsbb.BBDesc;
        getDisplayName(): string
        {
            return this.desc.name;
        }

        //参数组
        setInParamValue(index: number, value: any): void
        {
        }
        setInParmaValues(values: any[]): void
        {
        }
        getOutParamValue(index: number): any
        {
            if (index == 0)
                return 100;
            return null;
        }
        getOutParamValues(): any[]
        {
            return [100];
        }

        //行为组
        onInit(): void //进入状态
        {
        }
        onExit(): void //离开状态
        {

        }

        getExitState(): number
        {
            return -1;//没处理完
        }

        onUpdate(): void//表达式计算
        {
        }

        static reg()
        {
            var desc = new lighttool.tsbb.BBDesc();
            desc.name = "return";
            desc.exitNames = [];
            desc.inParamNames = ["number"];
            desc.inParamTypes = ["integer"];
            desc.outParamNames = [];
            desc.outParamTypes = [];
            //注册块
            lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new expr_return(); } });
        }
    }

    export class expr_addOne implements lighttool.tsbb.IBBAction_Expr
    {
        desc: lighttool.tsbb.BBDesc;
        getDisplayName(): string
        {
            return this.desc.name;
        }

        //参数组
        setInParamValue(index: number, value: any): void
        {
            if (index == 0)
            {
                this.value = value + 1;
            }
        }
        setInParmaValues(values: any[]): void
        {
            this.value = values[0] + 1;
        }
        getOutParamValue(index: number): any
        {
            if (index == 0)
                return this.value;
        }
        getOutParamValues(): any[]
        {
            return [this.value];
        }
        getReturnType(indata: any[]): string
        {
            return "integer";
        }
        //行为组
        value: number = null;
        run(): lighttool.tsbb.exprReturnValue
        {
            if (this.value == null)
                return lighttool.tsbb.exprReturnValue.InParamNotReady;
            else
                return lighttool.tsbb.exprReturnValue.Succ;
        }
        static reg()
        {
            var desc = new lighttool.tsbb.BBDesc();
            desc.name = "addone";
            desc.exitNames = [];
            desc.inParamNames = ["number"];
            desc.inParamTypes = ["integer"];
            desc.outParamNames = ["number"];
            desc.outParamTypes = ["integer"];
            //注册块
            lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new expr_addOne(); } });
        }
    }
    export class expr_add implements lighttool.tsbb.IBBAction_Expr
    {
        desc: lighttool.tsbb.BBDesc;
        getDisplayName(): string
        {
            return this.desc.name;
        }

        a: number;
        b: number;
        //参数组
        setInParamValue(index: number, value: any): void
        {
            if (index == 0)
            {
                this.a = value;
                this.value = this.a + this.b;
            }
            else if (index == 1)
            {
                this.b = value;
                this.value = this.a + this.b;
            }
        }
        setInParmaValues(values: any[]): void
        {
            this.a = values[0];
            this.b = values[1];
            this.value = this.a + this.b;
        }
        getOutParamValue(index: number): any
        {
            if (index == 0)
                return this.value;
        }
        getOutParamValues(): any[]
        {
            return [this.value];
        }
        getReturnType(indata: any[]): string
        {
            return "integer";
        }
        //行为组
        value: number = null;
        run(): lighttool.tsbb.exprReturnValue
        {
            if (this.value == null)
                return lighttool.tsbb.exprReturnValue.InParamNotReady;
            else
                return lighttool.tsbb.exprReturnValue.Succ;
        }
        static reg()
        {
            var desc = new lighttool.tsbb.BBDesc();
            desc.name = "add";
            desc.exitNames = [];
            desc.inParamNames = ["number", "number"];
            desc.inParamTypes = ["integer", "integer"];
            desc.outParamNames = ["number"];
            desc.outParamTypes = ["integer"];
            //注册块
            lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new expr_add(); } });
        }
    }

}